package com.basksoft.baskreport.demo.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.basksoft.baskreport.demo.ToolSpring;
import com.basksoft.report.console.BaskReportFilter;

@Configuration
public class ReportConfig implements WebMvcConfigurer,EnvironmentAware {
	
	@Bean
    public FilterRegistrationBean<BaskReportFilter> registerReportFilter() {
        FilterRegistrationBean<BaskReportFilter> registration = new FilterRegistrationBean<BaskReportFilter>(new BaskReportFilter());
        registration.addUrlPatterns("/*");
        registration.setName("reportFilter");
        registration.setOrder(1);  //值越小，Filter越靠前。
        return registration;
    }

    @Override
    public void setEnvironment(Environment environment) {
        ToolSpring.setEnvironment(environment);
    }
}
